<?php
/**
 * Created by PhpStorm.
 * User: 87976
 * Date: 2018/1/25
 * Time: 14:59
 */

namespace App\Services\Album;


use App\Abstracts\TemplateAbstract;
use App\Repositories\Album\AlbumTextRepository;

/**
 * Class AlbumTextService
 * @package App\Services\Album
 */
class AlbumTextService extends TemplateAbstract
{

    /**
     * @var AlbumTextRepository
     */
    protected $albumTextRepository;

    /**
     * AlbumTextService constructor.
     * @param AlbumTextRepository $albumTextRepository
     */
    public function __construct(AlbumTextRepository $albumTextRepository)
    {
        $this->albumTextRepository = $albumTextRepository;
    }

    /**
     * @author Jerry
     * @param array $data
     * @return array|mixed
     */
    public function handle(array $data)
    {
        if (empty($data)) {
            return [];
        }

        $text = $this->albumTextRepository->findAlbumTextByTemplateId($data['id']);

        $content = '';

        if ($text) {
            $content = $text->content;
        }

        $data['content'] = $content;

        unset($data['album_id']);

        return $data;
    }
}